#!/bin/bash

#set the target process
TARGET="tcpproxy"

#Infinite loop

while true; do
  # Check if the process is running
  if ps ax | grep -v grep | grep $TARGET > /dev/null
  then
    echo "$TARGET is running"
  else
    echo "$TARGET is not running, starting it up"
    # Start the process
    time=$(date +'%Y-%m-%d_%H-%M')
    mv out.log out_$time.log
    nohup ./$TARGET>out.log 2>&1 &
  fi

  # Sleep for 10 seconds
  sleep 10
done
